package mt.dummy;

import java.util.LinkedList;
import java.util.Queue;

import mt.Order;
import mt.comm.ServerComm;
import mt.comm.ServerSideMessage;

public class ServerCommDummy implements ServerComm {

	private Queue<ServerSideMessage> listOfMessages = new LinkedList<ServerSideMessage>();

	@Override
	public void start() {

	}

	@Override
	public boolean hasNextMessage() {
		boolean hasMessage = false;
		if (!listOfMessages.isEmpty())
			hasMessage = true;
		return hasMessage;
	}

	@Override
	public ServerSideMessage getNextMessage() {
		ServerSideMessage nextMessage = null;
		if (hasNextMessage()) {
			nextMessage = listOfMessages.poll();
		} else {
			while (nextMessage == null);
		}
		return nextMessage;
	}

	@Override
	public void sendError(String toNickname, String error) {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean clientIsConnected(String nickname) {
		for (ServerSideMessage m : listOfMessages)
			if (m.getSenderNickname().equals(nickname))
				return true;
		return false;
	}

	@Override
	public void disconnectClient(String nickname) {
//		for (int i = 0; i < listOfMessages.size(); i++) {
//			String tmpNick = listOfMessages.get(i).getSenderNickname();
//			if (tmpNick.equals(nickname)) {
//				listOfMessages.remove(i); // Remove-se utilizador da lista??
//			}
//		}
	}

	@Override
	public void sendOrder(String receiversNickname, Order order) {
		// TODO Auto-generated method stub

	}

	public Queue<ServerSideMessage> getListOfMessages() {
		return listOfMessages;
	}

	public void setListOfMessages(Queue<ServerSideMessage> listOfMessages) {
		this.listOfMessages = listOfMessages;
	}
	
	

}
